<template>
	<view class="container">
		<scroll-view class="list" v-if="list.length!=0" scroll-y="true" @scrolltolower="loadMore">
			<view class="list_item" @click="toDetail(item.order_sn)" v-for="item in list" :key="item.id">
				<view class="left">
					<view class="img">
						<image src="/static/img/agent/record.png" mode="widthFix"></image>
					</view>
					<view class="item_l">
						<text>{{item.nickname}}</text>
						<text class="time" v-if="item.use_time">用时{{item.use_time}}</text>
						<text class="time" v-else>正在使用中</text>
					</view>
				</view>

				<view class="item_r">
					+￥{{item.pay_money}}
				</view>
			</view>
		</scroll-view>
		<view class="empty" v-else>
			暂无使用记录
		</view>
	</view>
</template>

<script>
	import {
		usaRecord
	} from '../../../api/api.js'
	export default {
		data() {
			return {
				list: [],
				limit: 12,
				current_page: 1,
				total: 0,
				last_page: 1,
			}
		},
		onLoad() {
			this.getRecordList('')
		},
		methods: {
			toDetail(order_sn) {
				uni.navigateTo({
					url: '/pages/detail/detail?order_sn=' + order_sn
				})
			},
			loadMore() {
				if (this.current_page < this.last_page) {
					this.current_page += 1
					this.getRecordList('loadMore')
				} else {

				}
			},
			getRecordList(loadMore) {
				usaRecord({
					limit: this.limit,
					page: this.current_page
				}).then(res => {
					console.log(res)
					// this.list = res.data.data
					if (loadMore) {
						if (this.current_page <= this.last_page) {
							for (let i = 0; i < res.data.data.length; i++) {
								this.list.push(res.data.data[i])
							}
						} else {}
					} else {
						this.list = res.data.data
						this.total = res.data.total
						this.last_page = res.data.last_page
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100%;
		background-color: #f6f6f6;
	}

	.empty {
		width: 100%;
		min-height: 60upx;
		line-height: 60upx;
		text-align: center;
	}

	.list {
		width: 100%;
		min-height: 60upx;
		line-height: 60upx;
		text-align: center;
		height: 100%;
		background-color: #FFFFFF;
		// margin-top: 10upx;

		.list_item {
			width: calc(100% - 60upx);
			height: 130upx;
			margin: 0 auto;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1upx solid #f7f7f7;

			.left {
				display: flex;
				align-items: center;

				.img {
					width: 100upx;
					height: 100upx;
					background-color: #D8EFFF;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-right: 20upx;

					image {
						width: 100%;
					}
				}

				.item_l {
					height: 80%;
					display: flex;
					font-size: 28upx;
					flex-direction: column;
					justify-content: space-around;
					text-align: left;

					.time {
						color: #999999;
						font-size: 24upx;
					}
				}
			}



			.item_r {
				color: #45d3c4;
				font-size: 36upx;
			}

		}

	}
</style>
